package edu.washington.cs.sounddetector.server.api.methodresult;

import org.apache.commons.lang3.Validate;

import edu.washington.cs.sounddetector.server.api.MethodResult;
import edu.washington.cs.sounddetector.server.api.method.Classify;

public class ClassifyResult extends MethodResult<Classify>
{

    private String soundClass;
    private String detectorId;

    private ClassifyResult(boolean successful, FailureReason reason, String soundClass,
            String detectorId)
    {
        super(successful, reason);
        this.soundClass = soundClass;
        this.detectorId = detectorId;
    }

    private ClassifyResult()
    {
        this(true, null, null, null);
    }

    /**
     * @param soundClass
     *            the soundClass to set
     */
    public void setSoundClass(String soundClass)
    {
        this.soundClass = soundClass;
    }

    /**
     * @return if {@link #isSuccessful()} is true, returns the soundClass of the classified sound,
     *         otherwise returns null.
     */
    public String getSoundClass()
    {
        return this.soundClass;
    }

    /**
     * @return the detectorId that does not exist if {@link #isSuccessful()} returns false, null
     *         otherwise
     */
    public String getDetectorId()
    {
        return detectorId;
    }

    /**
     * @param detectorId
     *            the detectorId to set
     */
    public void setDetectorId(String detectorId)
    {
        this.detectorId = detectorId;
    }

    public static ClassifyResult success(String soundClass)
    {
        Validate.notBlank(soundClass);
        return new ClassifyResult(true, null, soundClass, null);
    }

    public static ClassifyResult failureDetectorIdDoesNotExist(String detectorId)
    {
        Validate.notBlank(detectorId);
        return new ClassifyResult(false, FailureReason.DETECTOR_ID_DOES_NOT_EXIST, null, detectorId);
    }
}
